package p.ithorns.support.license.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import p.ithorns.support.license.model.LicenseBody;
import p.ithorns.support.license.model.License;
import p.ithorns.support.license.service.GrantClientService;

/**
 * LicenseController
 *
 * @author Ht.L
 * @date 2023-12-13 09:43
 * @since 1.0.0
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class LicenseClientController {

    private final GrantClientService clientService;

    /**
     * 获取客户端ID
     *
     * @return ClientId
     */
    @GetMapping("/client/id")
    public String getClientId() throws Exception {
        return clientService.genClientId();
    }

    /**
     * 加载授权信息
     *
     * @throws Exception -
     */
    @GetMapping("/load")
    public void loadAuth() throws Exception {
        clientService.loadLocalAuth();
    }

    /**
     * 解密证书信息
     *
     * @param body -证书密文
     * @return License
     * @throws Exception -
     */
    @PostMapping("/decrypt")
    public License decrypt(@RequestBody LicenseBody body) throws Exception {
        return clientService.decrypt(body);
    }

}